using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;

namespace EBookReader.Library
{
    public class GZipWebReader : WebReader
    {
        protected override void TranslateBody(MemoryStream ms)
        {
            //ms.Position = 0;
            //DeflateStream gzStream = new DeflateStream(ms, CompressionMode.Decompress);
            //StreamReader sr = new StreamReader(gzStream);
            //string temp = sr.ReadToEnd();
            //MemoryStream newMs = new MemoryStream();
            //StreamWriter sw = new StreamWriter(newMs);
            //sw.Write(temp);
            //sr.Close();
            //base.TranslateBody(newMs);
            //ms.Position = 0;
            //StreamReader sr = new StreamReader(ms);
            //page.Buffer = sr.ReadToEnd();
            //sr.Close();
            ms.Position = 0;
            while (ms.ReadByte() != (byte)0x1F)
            {
            }
            ms.Position--;
            GZipStream gzStream = new GZipStream(ms, CompressionMode.Decompress);
            StreamReader sr = new StreamReader(gzStream, Encoding.GetEncoding(encode));
            page.Buffer = sr.ReadToEnd();
            sr.Close();
        }
    }
}
